<?php
session_start();
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);

if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
    echo "The file ". basename($_FILES["file"]["name"]). " has been uploaded.";
    echo "<br><a href='$target_file'>Click here to view your file</a>";
} else {
    echo "Sorry, there was an error uploading your file.";
}
?>
